<?php
	$access=array();
	$modify=array();
		
	foreach($permissions->result() as $permission){
		array_push($access, $permission->access);
		array_push($modify, $permission->modify);
	}
?>

<section class="content-header">
                    <h1>
                        Update Author Form
                        <small>Preview</small>
                    </h1>
                    <ol class="breadcrumb">
                        <li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li>
                        <li><a href="#">Update author form</a></li>
                        <li class="active">Author information</li>
                    </ol>
                </section>
<form role="form" action="<?php echo base_url();?>control-authors/update-author/<?php echo $this->uri->segment(3);?>" method="post">
<section class="content">
                    <div class="row">
                        <!-- left column -->
                        <div class="col-md-6">
                            <!-- general form elements -->
                            <div class="box box-primary">
                                <div class="box-header">
                                    <h3 class="box-title">Author information</h3>
                                </div><!-- /.box-header -->
                                <!-- form start -->
                                
                                    <div class="box-body">
                                        <div class="form-group">
                                            <label for="username">Username <span class="required">*</span></label>
                                            <input type="username" class="form-control" id="username" name="username" placeholder="Username" value="<?php echo $author->username;?>" required="required">
                                            <?php echo form_error('username');?>
                                        </div>
                                        <div class="form-group">
                                            <label for="email">Email <span class="required">*</span></label>
                                            <input type="email" class="form-control" id="email" name="email" placeholder="Email" value="<?php echo $author->email;?>" disabled="true">
                                            <?php echo form_error('email');?>
                                        </div>
                                        <div class="form-group">
                                            <label for="phone">Phone <span class="required">*</span></label>
                                            <input type="text" class="form-control" id="phone" name="phone" placeholder="Phone" value="<?php echo $author->phone;?>" required="required">
                                            <?php echo form_error('phone');?>
                                        </div>
                                        <div class="form-group">
                                            <label for="position">Position <span class="required">*</span></label>
                                            <input type="text" class="form-control" id="position" name="position" placeholder="Position" value="<?php echo $author->position;?>" required="required">
                                            <?php echo form_error('position');?>
                                        </div>
                                        <div class="form-group">
                                            <label for="address">Address</label>
                                            <textarea class="form-control" rows="7" name="address"><?php echo $author->address;?></textarea>
                                        </div>
                                        
                                        
                                    </div><!-- /.box-body -->

                                    <div class="box-footer">
                                        <button type="submit" class="btn btn-success"><span class="glyphicon glyphicon-saved"></span> Submit</button>
                                    </div>
                                
                            </div><!-- /.box -->

                            
                        </div><!--/.col (left) -->
                        <!-- right column -->
                        <div class="col-md-6">
                            <!-- general form elements disabled -->
                            <div class="box box-warning">
                                <div class="box-header">
                                    <h3 class="box-title">Author Authentication</h3>
                                </div><!-- /.box-header -->
                                <div class="box-body">
                                    
                                    	
                                        <!-- text input -->
                                        <div class="form-group">
                                            <label>Access Permission</label>
                                            <div class="scrollbox">
                                    		<div class="form-group">
                                    		<?php
                                    			$i_access=0;
                                    			foreach($modules as $module){
                                    				$module_id=$module->module_id;
													$name=$module->name;
													if($access[$i_access]=="YES"){
														$check_access="checked";
													}else{
														$check_access="";
													}
													
											?>
													<div class="checkbox">
		                                                <label>
		                                                    <input type="checkbox" name="module_access[]" value="<?php echo $module_id;?>" id="access<?php echo $module_id;?>" <?php echo $check_access;?>/>
		                                                    <?php echo str_replace("_", " ", $name);?>
		                                                </label>
		                                            </div>
											<?php
													$i_access++;
                                    			}
                                    		?>
                                            
                                        </div>

                                    	</div>
                                        </div>
                                        <div class="form-group">
                                            <label>&nbsp;</label>
                                            <button type="button" class="btn btn-primary" onClick="checkAllAccess(true);"><span class="glyphicon glyphicon-check"></span> Check All</button>
                                            <button type="button" class="btn btn-warning" onClick="checkAllAccess(false);"><span class="glyphicon glyphicon-unchecked"></span> Uncheck All</button>
                                        </div>
                                        <div class="form-group">
                                            <label>Modify Permission</label>
                                            <div class="scrollbox">
                                    		<div class="form-group">
                                            <?php
                                            	$i_modify=0;
                                    			foreach($modules as $module){
                                    				$module_id=$module->module_id;
													$name=$module->name;
													
													if($modify[$i_modify]=="YES"){
														$check_modify="checked";
													}else{
														$check_modify="";
													}
											?>
													<div class="checkbox">
		                                                <label>
		                                                    <input type="checkbox" name="module_modify[]" value="<?php echo $module_id;?>" id="modify<?php echo $module_id;?>" <?php echo $check_modify;?>/>
		                                                    <?php echo str_replace("_", " ", $name);?>
		                                                </label>
		                                            </div>
											<?php
												$i_modify++;
                                    			}
                                    		?>

                                        </div>

                                    	</div>
                                        </div>
                                        <div class="form-group">
                                            <label>&nbsp;</label>
                                            <button type="button" class="btn btn-primary" onClick="checkAllModify(true);"><span class="glyphicon glyphicon-check"></span> Check All</button>
                                            <button type="button" class="btn btn-warning" onClick="checkAllModify(false);"><span class="glyphicon glyphicon-unchecked"></span> Uncheck All</button>
                                        </div>

                                      
                                </div><!-- /.box-body -->
                            </div><!-- /.box -->
                        </div><!--/.col (right) -->
                    </div>   <!-- /.row -->
                </section><!-- /.content -->
               </form>